package com.wwj.app.v1;

import com.github.pagehelper.Page;
import com.wwj.core.wawa.entity.Player;
import com.wwj.core.wawa.entity.Room;
import com.wwj.core.wawa.service.IPlayerService;
import com.wwj.framework.controller.BaseController;
import com.wwj.framework.utils.ReturnData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/v1/rank")
public class RankController extends BaseController {

    @Resource
    private IPlayerService playerService;

    @RequestMapping("/list")
    @ResponseBody
    public ReturnData list(@RequestParam int roomId, @RequestParam(required = false) Integer pageNo, @RequestParam(required = false) Integer pageSize) {
        ReturnData returnData = new ReturnData();
        try {
            if(pageNo == null || pageNo == 0) {
                pageNo = 1;
            }
            if(pageSize == null || pageSize ==0) {
                pageSize = 10;
            }
            int offset = (pageNo - 1) * pageSize;
            int limit = pageSize;
            Page<Player> players = playerService.findRoomRankByPage(roomId, offset, limit);
            returnData.success(players);
        } catch (Exception e) {
            logger.error("", e);
            returnData.failure("系统错误,请联系客服");
        }
        return returnData;
    }
}
